package online.siwu.ansiconverter

import android.annotation.SuppressLint
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*

@SuppressLint("SetTextI18n")
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        init()
    }

    private fun init() {
        etIn.setText("中国A1")
        etIn.selectAll()
        btOK.setOnClickListener(oclOK)
        btClear.setOnClickListener(oclClear)
    }

    val oclOK = View.OnClickListener {
        var str = etIn.text.toString()
        if (str != "") {
            val  bytes = str.toByteArray(charset("GB18030"))
            str = ""
            for (b in bytes){
                str += b.toInt().toString(16)
            }
            etOut.setText(str)  //中文不对
        }
    }

    val oclClear = View.OnClickListener {
        etIn.setText("")
        etOut.setText("")
    }

}
